<?php
session_start();
include_once ("$basedir"."/Login/databaseconnection.php");

if(!loggedin())
{
	require_once ("$basedir"."/index.php");
}
   
   else
   {
	$School_Id=$_POST['School_Id'];
	$Exam_Name=$_POST['Exam_Name'];
   $Year=$_POST['Year'];
 
  if($School_Id!="Select One"&&$Exam_Name!="Select One"&&$Year!="Select One")
	   {
	   $result=mysql_query("SELECT * FROM exam WHERE School_Id='$School_Id' AND Exam_Name='$Exam_Name' AND Year='$Year'");
	   if(mysql_num_rows($result)==0)
   {

	   $_SESSION['errornorow']="Very sorry there is no result,Please check your inputs and try again!";
   }
   else
   {
   if($_SESSION['Access_Type']=="Administrator")
   {
    
	{
   	  $del=mysql_query("DELETE FROM exam WHERE School_Id='$School_Id' AND Exam_Name='$Exam_Name' AND Year='$Year'");
	if(mysql_affected_rows()!=0)
  {
$_SESSION['error']="This record is successfully deleted!";
 
  }

  if(mysql_affected_rows()==0)
  {
 $_SESSION['error']="Sorry unable to delete this record!";
  }
  }
   } 
    if($_SESSION['Access_Type']=="Teacher Incharge")
   {
   $NIC_Number=$_SESSION['NIC_Number'];
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
  
   if($School_Id==$Own_School_Id)
	{
		  $del=mysql_query("DELETE FROM exam WHERE School_Id='$School_Id' AND Exam_Name='$Exam_Name' AND Year='$Year'");
	if(mysql_affected_rows()!=0)
  {
$_SESSION['error']="This record is successfully deleted!";
  }
 if(mysql_affected_rows()==0)
  {
 $_SESSION['error']="Sorry unable to delete this record!";
  }
  }
  else
  {
  $_SESSION['errornot']="Access denied,Sorry you are not allowed!";
  }
  }
  }
  else
  {
  $_SESSION['errornot2']="Sorry you are not an authorised user!";
  }
  }
  }
 if($School_Id=="Select One"||$Exam_Name=="Select One"||$Year=="Select One")
	   {
		   $_SESSION['errorin']="Please select the School Id,Exam name and Year!";
   	   }  
   }
  ?>